<?php

namespace app\admin\controller;

use app\common\controller\AdminBaseController;

class ConfigController extends AdminBaseController
{
    protected function initialize()
    {
        parent::initialize();
        $this->server = model('server.config');
    }

    public function getConfigListPageOp()
    {
        $requestData = validateRequestParam('config', 'getListPage');
        $responseData['meta'] = ['code' => 1, 'msg' => lang('GET_SUCCESS')];
        $responseData['data'] = $this->server->getListPage($requestData);

        return $responseData;
    }

    public function saveConfigAddOp()
    {
        $requestData = validateRequestParam('config', 'saveAdd');
        $responseData['meta'] = ['code' => 1, 'msg' => lang('SAVE_SUCCESS')];
        $responseData['data'] = $this->server->saveAdd($requestData);

        return $responseData;
    }

    public function getConfigRowOp()
    {
        $requestData = validateRequestParam('config', 'getRow');
        $responseData['meta'] = ['code' => 1, 'msg' => lang('GET_SUCCESS')];
        $responseData['data'] = $this->server->getRow($requestData);

        return $responseData;
    }

    public function saveConfigEditOp()
    {
        $requestData = validateRequestParam('config', 'saveEdit');
        $responseData['meta'] = ['code' => 1, 'msg' => lang('SAVE_SUCCESS')];
        $responseData['data'] = $this->server->saveEdit($requestData);

        return $responseData;
    }

    public function saveConfigDelOp()
    {
        $requestData = validateRequestParam('config', 'getRow');
        $responseData['meta'] = ['code' => 1, 'msg' => lang('DEL_SUCCESS')];
        $responseData['data'] = $this->server->saveDel($requestData);

        return $responseData;
    }

    public function getCategoryConfigOp()
    {
        $postData = validateRequestParam('config', 'getCategoryList');
        $responseData['meta'] = [
            'code' => 1,
            'msg' => '获取指定分类成功',
        ];
        $responseData['data'] = $this->server->getCategoryList($postData);

        return $responseData;
    }

    public function saveCategoryConfigOp()
    {
        $postData = validateRequestParam('config', 'saveCategoryList');
        $responseData['meta'] = [
            'code' => 1,
            'msg' => '保存配置成功',
        ];
        $responseData['data'] = $this->server->saveCategoryConfig($postData);

        return $responseData;
    }

    public function getTagConfigOp()
    {
        $postData = validateRequestParam('config', 'getTagConfig');
        $responseData['meta'] = [
            'code' => 1,
            'msg' => '获取配置内容成功',
        ];
        $responseData['data'] = $this->server->getTagConfig($postData);

        return $responseData;
    }
}
